/**
 * 
 */
package com.jkl.service.project;

import java.util.List;

import com.jkl.entity.project.dto.VillageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jkl.comm.service.FileService;
import com.jkl.dao.project.PJProjectExtendMapper;
import com.jkl.dao.project.PJProjectMapper;
import com.jkl.entity.bsAddition.BsAddition;
import com.jkl.entity.project.extend.PJVillage;
import com.jkl.service.project.inter.IPJProjectExtendService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author: HXH
 * @Description:
 */
@Slf4j
@Service
public class PJProjectExtendService implements IPJProjectExtendService {
	@Autowired
	private PJProjectExtendMapper projectExtendMapper;
	@Autowired
	private FileService fileService;
	@Autowired
	private PJProjectMapper pJProjectMapper;

	@Override
	public int addVillage(PJVillage param, List<MultipartFile> fileList) {
		int num = projectExtendMapper.addVillage(param);
		int rowId = param.getRowId();
		if (!CollectionUtils.isEmpty(fileList)) {
			for (int i = 0; i < fileList.size(); i++) {
				MultipartFile file = fileList.get(i);
				String fileUrl = fileService.fileUpload(file);
				BsAddition bsAddition = new BsAddition();
				bsAddition.setAddType(1);
				bsAddition.setSourceTable("pj_village");
				bsAddition.setSourceId(rowId);
				bsAddition.setAddName(file.getOriginalFilename());
				bsAddition.setAddUrl(fileUrl);
				bsAddition.setSequence(1);
				bsAddition.setStatus(1);
				pJProjectMapper.addBsAddition(bsAddition);
			}
		}
		return num;
	}

	@Override
	public PageInfo<VillageDTO> queryVillageList(PJVillage param) {
		PageHelper.startPage(param.getCurrentPage(), param.getPageSize());
		if (param.getDate() != null){
			param.setDate1(param.getDate().get(0));
			param.setDate2(param.getDate().get(1));
		}
		List<VillageDTO> list = projectExtendMapper.queryVillageList(param);
		return new PageInfo<>(list);
	}

}
